<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\YiJingIntroductionStore;
use App\YiJingIntroduction;
use Illuminate\Http\Request;

class YiJingIntroductionController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $orderBy = $request->order_by ? $request->order_by : $this->orderBy;
        $orderType = $request->order_type ? $request->order_type : $this->orderType;
        $pageSize = $request->page_size ? $request->page_size : $this->pageSize;
        $lists = YiJingIntroduction::orderBy($orderBy, $orderType)->with(['sort']);
        if ($request->get('type')) {
            $lists = $lists->where('type', $request->type);
        }
        return $lists->paginate($pageSize);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(YiJingIntroductionStore $request)
    {
        YiJingIntroduction::create($request->only(['introduction', 'type']));
        return response(['message' => '创建成功']);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\YiJingIntroduction $yiJingIntroduction
     * @return \Illuminate\Http\Response
     */
    public function show(YiJingIntroduction $yiJingIntroduction)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\YiJingIntroduction $yiJingIntroduction
     * @return \Illuminate\Http\Response
     */
    public function edit(YiJingIntroduction $yiJingIntroduction)
    {
        //
    }

    /**
     * @param YiJingIntroductionStore $request
     * @param YiJingIntroduction $YiJingIntroduction
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function update(YiJingIntroductionStore $request, YiJingIntroduction $YiJingIntroduction)
    {
        $YiJingIntroduction->update($request->only(['introduction', 'type']));
        return response(['message' => '修改成功']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\YiJingIntroduction $yiJingIntroduction
     * @return \Illuminate\Http\Response
     */
    public function destroy(YiJingIntroduction $yiJingIntroduction)
    {
        $yiJingIntroduction->delete();
        return response(['message' => '删除成功']);
    }
}
